﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity.Framework;

using System.Data.Objects;

namespace Business.Operations
{
    public class KullaniciNfsOperation
    {
        private static HPDMASEntities db = new HPDMASEntities();

        public KullaniciNfsOperation()
        {

        }

        public static List<KullaniciNfs> KullaniciNfsGetAll()
        {
            var kullaniciNfsListesi = db.KullaniciNfs.ToList();
            return kullaniciNfsListesi;
        }

        public static KullaniciNfs KullaniciGetByKullaniciNfsId(int kullaniciNfsId)
        {
            var kullaniciNfs = (from c in db.KullaniciNfs where c.KullaniciNfsID == kullaniciNfsId select c).First();
            return kullaniciNfs;
        }

        public static void KullaniciNfsDelete(int kullaniciNfsId)
        {
            //db.gsp_KullaniciDelete(kullaniciId);
            KullaniciNfs k = (from c in db.KullaniciNfs where c.KullaniciNfsID == kullaniciNfsId select c).First();
            db.DeleteObject(k);
            db.SaveChanges();
        }

        public static void KullaniciNfsUpdate(KullaniciNfs kullaniciNfs)
        {
            db.KullaniciNfs.ApplyCurrentValues(kullaniciNfs);
            db.SaveChanges();
        }

        public static string KullaniciNfsTcKimlikNoGetByKullaniciNfsTcKimlikNo(string kullaniciNfsTcKimlikNo)
        {
            return db.KullaniciNfs.
                Where(c => c.KullaniciNfsTCKimlikNo == kullaniciNfsTcKimlikNo).
                Select(c => c.KullaniciNfsTCKimlikNo).SingleOrDefault();
        }

        public static KullaniciNfs KullaniciNfsGetByKullaniciId(int kullaniciId)
        {
            var k = db.KullaniciNfs.
                Where(c => c.KullaniciID == kullaniciId).
                Select(c => c).FirstOrDefault();
            return k;
        }

        public static void KullaniciNfsInsert(KullaniciNfs kullaniciNfs)
        {
            db.KullaniciNfs.AddObject(kullaniciNfs);
            db.SaveChanges();
        }

        /// <summary>
        /// Lisans No'ya göre ve TC Kimlik No'ya göre isim getirme.
        /// </summary>
        /// <param name="sehirId"></param>
        /// <returns></returns>
        public static List<string> KullaniciAdiSoyadiGetBySehirId(int sehirId)
        {
            var kullaniciAdiSoyadi = db.KullaniciNfs.
                Where(c => c.Kullanici.SehirID == sehirId).
                Select(c => c.KullaniciNfsAdi + " " + c.KullaniciNfsSoyadi).ToList();
            return kullaniciAdiSoyadi;
        }

        public static int KullaniciNfsIdGetByKullaniciId(int kullaniciId)
        {
            var kullaniciNfsId = db.KullaniciNfs.
                Where(c => c.KullaniciID == kullaniciId).
                Select(c => c.KullaniciNfsID).First();
            return kullaniciNfsId;
        }

        public static int KullaniciNfsIdGetByKullaniciAdiSoyadi(string kullaniciAdiSoyadi)
        {
            var kullaniciNfsId = db.KullaniciNfs.Where(c => c.KullaniciNfsAdi + " " + c.KullaniciNfsSoyadi == kullaniciAdiSoyadi).
                Select(c => c.KullaniciNfsID).FirstOrDefault();
            return kullaniciNfsId;
        }
    }
}
